package cn.youqu.happy.module.youqu.dal.mysql.userBlack;

import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.framework.mybatis.core.mapper.BaseMapperX;
import cn.youqu.happy.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.youqu.happy.module.youqu.controller.admin.userBlack.vo.UserBlackExportReqVO;
import cn.youqu.happy.module.youqu.controller.admin.userBlack.vo.UserBlackPageReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userBlack.UserBlackDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户黑名单 Mapper
 *
 * @author 王其岩 20112001045
 */
@Mapper
public interface UserBlackMapper extends BaseMapperX<UserBlackDO> {
    UserBlackDO findByIdAndUid(@Param("id") Integer id, @Param("uid") Long uid);

    UserBlackDO findOneByUidAndTargetId(@Param("uid") Long uid, @Param("targetId") Long targetId);

    List<UserBlackDO> findAllByTargetId(@Param("targetId") Long targetId);


    default PageResult<UserBlackDO> selectPage(UserBlackPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserBlackDO>()
                .eqIfPresent(UserBlackDO::getUid, reqVO.getUid())
                .eqIfPresent(UserBlackDO::getTargetId, reqVO.getTargetId())
                .eqIfPresent(UserBlackDO::getBlackType, reqVO.getBlackType())
                .betweenIfPresent(UserBlackDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserBlackDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserBlackDO::getId));
    }

    default List<UserBlackDO> selectList(UserBlackExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserBlackDO>()
                .eqIfPresent(UserBlackDO::getUid, reqVO.getUid())
                .eqIfPresent(UserBlackDO::getTargetId, reqVO.getTargetId())
                .eqIfPresent(UserBlackDO::getBlackType, reqVO.getBlackType())
                .betweenIfPresent(UserBlackDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserBlackDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserBlackDO::getId));
    }

}
